{include file="public/header" /}
<!--main content start-->
<section class="main-content-wrapper">
    <section id="main-content">
        <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">关联商品新增</h3>
                </div>
                <div class="panel-body">
                <div class="form-horizontal form-border">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">被关联商品：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="title" name="title" autocomplete="off" disabled value="{$data.title|default=''}">
                        </div>
                    </div>
                    {volist name="lists" id="vo"}
                    <div class="form-group add_con">
                        <label class="col-sm-2 control-label">关联商品：</label>
                        <div class="col-sm-2">
                            <input type="text" class="form-control gl_title" placeholder="关联标题" value="{$vo.title}">
                        </div>
                        <div class="col-sm-2">
                            <input type="text" class="form-control gl_link" placeholder="关联地址" value="{$vo.link}">
                        </div>
                        <span class="del_this" data-id="{$vo.id}" style="color: red;cursor: pointer;">删除</span>
                    </div>
                    {/volist}
                    <div class="form-group add_con">
                        <label class="col-sm-2 control-label">关联商品：</label><div class="col-sm-2">
                        <input type="text" class="form-control gl_title" placeholder="关联标题" value="">
                    </div>
                        <div class="col-sm-2">
                            <input type="text" class="form-control gl_link" placeholder="关联地址" value="">
                        </div>
                    </div>
                </div>
                    <div class="panel-body">
                        <button type="submit" class="btn btn_5 btn-lg btn-default w_update">保存并新增关联商品</button>
                        <a href="/admin/sale/index" class="btn btn_5 btn-lg btn-default">返回商品列表</a>
                    </div>
                </div>
            </div>
        </div>
        </div>
    </section>
</section>
<style>
    @media (min-width: 768px){
        .form-horizontal .control-label {
             text-align: left;
        }
    }
</style>
<script>
    htmls = '<div class="form-group add_con"><label class="col-sm-2 control-label">关联商品：</label><div class="col-sm-2"><input type="text" class="form-control gl_title" placeholder="关联标题" value=""></div><div class="col-sm-2"><input type="text" class="form-control gl_link" placeholder="关联地址" value=""></div><span class="del_this" style="color: red;cursor: pointer;">删除</span></div>'
    $(document).on('click','.w_update',function(){
        var gl_title = $('.add_con:last .gl_title').val();
        var gl_link = $('.add_con:last .gl_link').val();
        console.log(gl_title);
        console.log(gl_link);
        $('.form-border').append(htmls);
        $.ajax({
            type: "post",  //提交方式
            url: "/admin/sale/sale_status",//路径
            data: {'id':{$Request.get.id},'gl_title':gl_title,'gl_link':gl_link},
            dataType: "json",
            success: function (data) {
                if(data.status==0){
                    location.reload();
                }
                if(data.status==2){
                    alert('系统错误，请刷新页面!');
                }
                if(data.status==3){
                    alert(data.msg);
                }
            }
        });
    });
    $(document).on('click','.del_this',function(){
        var id = $(this).attr('data-id');
        $.ajax({
            type: "post",  //提交方式
            url: "/admin/sale/del_sale_relation",//路径
            data: {'id':id},
            dataType: "json",
            success: function (data) {
            if(data.status==0){
                location.reload();
            }
            if(data.status==3){
                alert(data.msg);
            }
        }
    });
        $(this).parent('div').remove();
    });
</script>
<!--百度编辑器插件-->
<script type="text/javascript" charset="utf-8" src="/web_admin/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/web_admin/ueditor/ueditor.all.min.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="/web_admin/ueditor/lang/zh-cn/zh-cn.js"></script>

<!--时间插件-->
<script src="/web_admin/js/bootstrap-datetimepicker.min.js"></script>
<link href="/web_admin/css/datetimepicker.css" rel='stylesheet' type='text/css' />
<script>
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');
    var ue = UE.getEditor('editor1');
</script>
<script>
    /**
     * 从 file 域获取 本地图片 url
     */
    function getFileUrl(sourceId) {
        var url;
        if (navigator.userAgent.indexOf("MSIE")>=1) { // IE
            url = document.getElementById(sourceId).value;
        } else if(navigator.userAgent.indexOf("Firefox")>0) { // Firefox
            url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));
        } else if(navigator.userAgent.indexOf("Chrome")>0) { // Chrome
            url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));
        }
        return url;
    }
    /**
     * 将本地图片 显示到浏览器上
     */
    function preImg(sourceId, targetId) {
        var url = getFileUrl(sourceId);
        var imgPre = document.getElementById(targetId);
        imgPre.src = url;
    }
</script>
<!--main content end-->
{include file="public/footer" /}